package sorting;

public class QuickSort {
	
	public static void main(String[] args){
		int[] arr1 ={4,7,4,1,0,10,-1};
		quickSort(arr1,0,arr1.length-1);
		print(arr1);
		
	}
	
	public static void quickSort(int[] arr, int begin, int end){
		if(begin>=end)
			return;
		int i =begin-1, j=begin;
		for(;j<end;j++){
			if(arr[j]<=arr[end]){
				swap(arr, i+1, j);
				i++;
			}
		}
		swap(arr, i+1, end);
		quickSort(arr, begin, i);
		quickSort(arr, i+2, end);
	}
	
	private static void swap(int[]arr, int i, int j){
		int tmp = arr[i];
		arr[i] = arr[j];
		arr[j] = tmp;
	}
	
	private static void print(int[] arr){
		for(int num: arr){
			System.out.print(num);
			System.out.print(", ");
		}
		System.out.print("\r\n ");
	}

}
